package net.onecloud.onecloud.talk;

import android.app.Activity;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import net.onecloud.onecloud.R;
import net.onecloud.onecloud.adapter.EnterpriseAdapter;
import net.onecloud.onecloud.base.BasePage;
import net.onecloud.onecloud.model.ResultEnterprise;
import net.onecloud.onecloud.network.NetWork;
import net.onecloud.onecloud.utils.RecycleViewDivider;
import net.onecloud.onecloud.utils.T;

import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by zaizai on 16/7/26.
 */
public class TalkPage extends BasePage {

    private SwipeRefreshLayout mSwipeRefreshLayout;
    private RecyclerView mRecyclerView;
    private EnterpriseAdapter mEnterpriseAdapter;
    private RecyclerView.LayoutManager mLayoutManager;


    Observer<ResultEnterprise> queryEnterpriseObserver = new Observer<ResultEnterprise>() {
        @Override
        public void onCompleted() {


        }

        @Override
        public void onError(Throwable e) {

        }

        @Override
        public void onNext(ResultEnterprise resultEnterprise) {
            if (resultEnterprise.getSuccess() == 1) {
                mEnterpriseAdapter.setNewData(resultEnterprise.getData());
            }

        }
    };

    public TalkPage(Activity activity) {
        super(activity);
        initView();
        initListener();
    }

    private void initListener() {
    }

    public void initView() {
        View view = View.inflate(mActivity, R.layout.page_talk, null);
        mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.m_swiperefresh);
        mRecyclerView = (RecyclerView) view.findViewById(R.id.m_recyclerview);
        mLayoutManager = new LinearLayoutManager(mActivity);
        mRecyclerView.setLayoutManager(mLayoutManager);
        mRecyclerView.setHasFixedSize(true);
        mRecyclerView.addItemDecoration(new RecycleViewDivider(mActivity, LinearLayoutManager.VERTICAL));
        mEnterpriseAdapter = new EnterpriseAdapter();
        mRecyclerView.setAdapter(mEnterpriseAdapter);
        this.mFrameLayoutContent.addView(view);
    }

    @Override
    public void initData() {
        NetWork.getEnterpriseApi()
                .query1()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(queryEnterpriseObserver);

    }
}
